home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_12.lha / 6_12 / 6_12a.c next >
Text File  |  1993-08-08  |  434b  |  26 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <stream.h>
  6.  
  7. xtern int atoi(const char*);
  8.  
  9. / calculate n!
  10. nt fact(int n)
  11.  
  12.    if (n < 2)
  13. return 1;
  14.    else
  15. return n * fact(n - 1);
  16.  
  17.  
  18. / print out n! for each of the arguments
  19. ain(int, char**argv)
  20.  
  21.    while (*++argv)
  22. cout << *argv << "!=" <<
  23.     fact(atoi(*argv)) << "\n";
  24.    return 0;
  25.  
  26.